#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-12-10 9:01 上午
# @Author  : yangdy
# @File    : 2020-12-10.860.柠檬水找零
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        a5, a10, a20 = 0, 0, 0
        for b in bills:
            if b == 5:
                a5 += 1
            elif b == 10:
                if a5 <= 0:
                    return False
                else:
                    a5 -= 1
                    a10 += 1
            elif b == 20:
                if not ((a10 > 0 and a5 > 0) or (a5 > 3)):
                    return False
                else:
                    if a10 > 0 and a5 > 0:
                        a5, a10 = a5-1, a10-1
                    else:
                        a5 -= 3
                    a20 += 1
        return True


questions = [
    ([5, 5, 5, 10, 20],),
    ([5, 5, 10],),
    ([10, 10],),
    ([5, 5, 10, 10, 20],),
]

work(questions, lambda q: Solution().lemonadeChange(q[0]))
